package com.nts.bupna;

import org.antlr.runtime.Parser;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.RecognizerSharedState;
import org.antlr.runtime.TokenStream;

import com.nts.bupna.errors.ConsoleReporter;
import com.nts.bupna.errors.Error;
import com.nts.bupna.errors.ParserError;
import com.nts.bupna.errors.Reporter;

public abstract class AbstractBParser extends Parser {

    private Reporter reporter = new ConsoleReporter();

    public AbstractBParser(final TokenStream input) {
        super(input);
    }

    public AbstractBParser(final TokenStream input, final RecognizerSharedState state) {
        super(input, state);
    }

    @Override
    public void displayRecognitionError(final String[] tokenNames, final RecognitionException e) {
        final String header = getErrorHeader(e);
        final String message = getErrorMessage(e, tokenNames);
        final Error error = new ParserError(header, message, e);
        reporter.reportError(error);
    }

    public Reporter getReporter() {
        return reporter;
    }

    public void setReporter(final Reporter reporter) {
        this.reporter = reporter;
    }
}

